/**
*      author: Y_Yao
*      created: 2024-12-16 12:29:35
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 7;
int n,m;
vector<pair<int,int>> v;

void solve()
{
    cin >> n >> m;
    int ans = 0;
    for(int i = 1;i <= n;i++)
    {
        int l,r;
        cin >> l >> r;
        v.push_back({l,r});
    }
    sort(v.begin(),v.end());

    int p = v.size() - 1;
    int rmin = m + 1;
    for(int l = m;l >= 1;l--)
    {
        while(p >= 0 && v[p].first >= l)
        {
            rmin = min(rmin,v[p].second);
            p--;
        }
        ans += rmin - l;
    }
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}